package com.huayue.service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huayue.dao.*;
import com.huayue.entity.EleTree;
import com.huayue.entity.Role;

/**
 * 角色
 */
@Service
public class RoleService extends BaseService<Role> {

    @Autowired
    MenuDao menuDao;

    @Autowired
    RoleDao roleDao;

    @Autowired
    AuthorityDao authorityDao;

    @Autowired
    DepartmentDao departmentDao;

    public DepartmentDao getDepartmentDao() {
        return departmentDao;
    }

    @Override
    public BaseDao<Role> getDao() {
        return roleDao;
    }

    public List<Map<String, Object>> findAllTopRole() {
        return roleDao.findAllTopRole();
    }

    public int authorityInsertBatch(List<EleTree> entity, Object... obj) {
        return authorityDao.insertBatch(entity, obj);
    }

    public List<Map<String, Object>> menuGoTree() {
        return menuDao.findAllTOTree();
    }

    public List<Integer> menuGoTreeByRoleId(Role role) {
        List<Integer> finalList = new ArrayList<Integer>();
        List<Map<String, Object>> DBList = menuDao.findAllByRoleIdNoTree(role);
        Iterator<Map<String, Object>> iterator = DBList.iterator();
        while (iterator.hasNext()) {
            Map<String, Object> item = iterator.next();
            int menuint = -1;
            for (Map.Entry entry : item.entrySet()) {
                if (entry.getKey().equals("id")) {
                    menuint = Integer.valueOf(entry.getValue().toString());
                }
            }
            finalList.add(menuint);
        }
        return finalList;
    }
}
